package com.eascs.workflow.timeEffective.dubbo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.workflow.common.entity.wf.ProcessTaskMain;
import com.eascs.workflow.common.entity.wf.ProcessTaskNode;
import com.eascs.workflow.common.service.timeEffective.TimeffectiveDubboService;
import com.eascs.workflow.common.vo.ModelResult;
import com.eascs.workflow.timeEffective.dao.TimeffectiveDao;
import com.eascs.workflow.timeEffective.service.TaskServer;

@Service
public class TimeffectiveDubboServiceImpl implements TimeffectiveDubboService{
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private TaskServer taskServer;
	
	@Autowired
	private TimeffectiveDao timeffectiveDao;
	
	private static final int PAGE_SIZE   = 100;

	@Override
	public ModelResult<Boolean> timeffectiveNodeTask(ProcessTaskNode taskNode) {
		
		return taskServer.wfProcessNodeTask(taskNode);
	}
	
	@Override
	public ModelResult<Boolean> timeffectiveMainTask(ProcessTaskMain taskMain) {
		return taskServer.wfProcessMainTask(taskMain);
	}

	@Override
	public ModelResult<List<ProcessTaskNode>> queryProcessNodeByPage(int pageSize, int pageIdex) {
		logger.info("时效节点数据计算pageSize[{}],pageIdex[{}]", pageSize,pageIdex);
		ModelResult<List<ProcessTaskNode>> modelResult=new ModelResult<>();
		try {
			if (pageSize == 0) {
				pageSize = PAGE_SIZE;
			}
			List<ProcessTaskNode> list = timeffectiveDao.queryProcessNodeByPage(pageSize, pageIdex);
			modelResult.withModel(list);
		} catch (Exception e) {
			logger.info("时效定时任务报错 method queryProcessNodeByPage:[{}]", e.getMessage());
			modelResult.withError("TimeffectiveDubboService queryProcessNodeByPage error", e.getMessage());
		}
		return modelResult;
	}

	@Override
	public ModelResult<List<ProcessTaskMain>> queryProcessMainByPage(int pageSize, int pageIdex) {
		logger.info("时效流程数据计算pageSize[{}],pageIdex[{}]", pageSize,pageIdex);
		ModelResult<List<ProcessTaskMain>> modelResult=new ModelResult<>();
		try {
			if (pageSize == 0) {
				pageSize = PAGE_SIZE;
			}
			List<ProcessTaskMain> list = timeffectiveDao.queryProcessMainByPage(pageSize, pageIdex);
			modelResult.withModel(list);
		} catch (Exception e) {
			logger.info("时效定时任务报错 method queryProcessMainByPage:[{}]", e.getMessage());
			modelResult.withError("TimeffectiveDubboService queryProcessMainByPage error", e.getMessage());
		}
		return modelResult;
	}

	

}
